package com.example.showlocation;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.Looper;
import android.util.Log;

import androidx.annotation.Nullable;

import com.tencent.map.geolocation.TencentLocation;
import com.tencent.map.geolocation.TencentLocationListener;
import com.tencent.map.geolocation.TencentLocationManager;
import com.tencent.map.geolocation.TencentLocationRequest;

public class RequestSingleFreshLocationService extends Service {
    TencentLocationManager locationManager;
    TencentLocationRequest locationRequest;

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {

        return null;
    }
    class MyLocationListener implements TencentLocationListener {
        @Override
        public void onLocationChanged(TencentLocation tencentLocation, int error, String reason) {

            Log.d(this.toString()+":", tencentLocation.getLatitude()+","+tencentLocation.getLongitude());
            Log.d(this.toString()+":", "onLocationChanged");
        }

        @Override
        public void onStatusUpdate(String s, int i, String s1) {

        }

    }
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d(this.toString()+":", ",");

        locationManager = TencentLocationManager.getInstance(this);
        locationRequest = TencentLocationRequest.create();
        locationRequest.setGpsFirst(true);
        MyLocationListener mLocationListener=new MyLocationListener();
        TencentLocationManager.setUserAgreePrivacy(true);
        locationManager.requestSingleFreshLocation(locationRequest,mLocationListener , Looper.myLooper());
        return  START_STICKY;
    }




}
